import React, { Component } from 'react'
import { connect } from 'dva';
import FormList from './components/FormItem';
import { KEYS_EDIT } from './enum';

interface Props {
  dispatch: Function,
  data: {
    id?: number,
    x?: number,
    y?: number,
    name: string,
    image?: string,
    areaId?: number,
    relationUserPhone: string;
    areaName?: string,
    ownerCode: number,
    mobile?: string;
    registerTime?: string,
    bindStatus?: String,
    onlyTask?: String,
    autoCall?: String,
    chemical?: String,
    industryType?: string,
    relationId?: string,
    relationUser?: string,
    propertyOwnerName: string,
    trade?: string
  },
  match: {
    params: {
      id: number
    }
  },
  details: object
}



@connect(({ owner }) => ({
  data: owner.editDetails
}))
class Update extends Component<Props, any> {

  componentDidMount() {
    const { dispatch, match } = this.props;
    const { params } = match;
    dispatch({
      type: 'owner/queryEditInfo',
      payload: {
        id: params.id,
        keys: KEYS_EDIT
      }
    })
  }

  render() {
    let { data } = this.props
   data.trade && (data = { ...data, trade: `${data.trade}` })
    return (
      <section style={{ background: '#fff' }}>
        <FormList data={data} key={Date.now()} />
      </section>
    );
  }
}

export default Update;
